<template>
  <div class="newList">
    <div class="newListHeader">
    <top :title="title">
      <router-link to="/home" slot="back"> <!--slot插槽-->
        <mt-button icon="back">返回</mt-button>
      </router-link>
    </top>
    </div>
    <div class="newListList">
      <router-link v-slot="{ navigate }" custom :to="'/home/newList/newDetails/'+ item.newsId" class="newListItem" v-for="(item) in list" :key="item.newsId">
        <div @click="navigate"><!--v-slot="{ navigate }  @click="navigate"-->
          <img class="newListItem_img" :src="item.pics" alt="" />
          <div class="newListItem_content">
            <p class="newListItem_title">{{item.title}}</p>
            <p class="newListItem_information">
              <span class="newListItem_time">{{item.joinTime}}</span>
              <span class="newListItem_click">点击：{{item.hits}}次</span>
            </p>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
import Top from '../components/top'
export default {
  name: 'NewList',
  components: {
    Top
  },
  data () {
    return {
      title: '新闻列表',
      list: []
    }
  },
  mounted () {
    //axios.get(远程地址).then(请求成功或失败的处理)
    this.$http.get('/news/getList?categoryId=-1&page=1&size=20').then((res)=>{
      console.log(res);
      this.list = res.data.data.rows;
    })
  }
}
</script>

<style>
.newList{
  height: calc(100% - 55px);
  display: flex;
  flex-direction: column;
}
.newListHeader{
  height: 40px;
}
.newListList{
  flex: 1;
  width: 100%;
  height: calc(100% - 55px);
  overflow-y: auto;
}
.newListItem {
  display: flex;
  height: 60px;
  padding: 15px;
  border-bottom: 1px solid LightGrey;
}
.newListList .newListItem:last-child{
  border: none;
}
.newListItem_img {
  width: 100%;
  height: 100%;
  overflow: hidden;
  flex: 1;
  padding-right: 10px;
  object-fit: cover;
}
.newListItem_content {
  flex: 3;
  display: flex;
  flex-direction: column;
  text-align: left;
}
.newListItem_title{
  flex: 1;
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.newListItem_information {
  display: flex;
  margin: 0;
  font-size: 12px;
  color: LightGrey;
}
.newListItem_time{
    flex: 1;
}
</style>
